package config

import (
	"common/helper"
	"database/sql"
)

const (
	PromoDeposit_First  = 1 //首存
	PromoDeposit_Common = 2 //次存
)

type PromoDepositConfig struct {
	Id        int     `json:"id" cbor:"id" db:"id"`
	Name      string  `json:"name" cbor:"name" db:"name"`                   //配置名称
	Bonus     float64 `json:"bonus" cbor:"bonus" db:"bonus"`                //奖金比例
	Flow      float64 `json:"flow" cbor:"flow" db:"flow"`                   //流水倍数
	MaxAmount float64 `json:"max_amount" cbor:"max_amount" db:"max_amount"` //最大金额
	MinAmount float64 `json:"min_amount" cbor:"min_amount" db:"min_amount"` //最小金额
	Ty        int     `json:"ty" cbor:"ty" db:"ty"`                         //1首存2次存
}

var g_PromoDepositCfgList []PromoDepositConfig

func PromoDepositCfgSetRow(rows *sql.Rows) {
	var tVal PromoDepositConfig
	var err error
	err = rows.Scan(&tVal.Name, &tVal.Bonus, &tVal.Flow, &tVal.MaxAmount, &tVal.MinAmount, &tVal.Ty)
	if err != nil {
		helper.InfoLog("PromoDepositCfgSetRow,scan err")
		return
	}
	g_PromoDepositCfgList = append(g_PromoDepositCfgList, tVal)
}

func PromoDepositCfgRemove() {
	g_PromoDepositCfgList = []PromoDepositConfig{}
}

func PromoDepositConfigList(ty int) []PromoDepositConfig {
	var configs []PromoDepositConfig
	var config PromoDepositConfig
	for _, i := range g_PromoDepositCfgList {
		if i.Ty == ty {
			config.Id = i.Id
			config.Name = i.Name
			config.Bonus = i.Bonus
			config.Flow = i.Flow
			config.MaxAmount = i.MaxAmount
			config.MinAmount = i.MinAmount
			config.Ty = i.Ty
			configs = append(configs, config)
		}
	}
	return configs
}

func getPromoDepositConfig(ty int, amount float64) PromoDepositConfig {

	for _, val := range g_PromoDepositCfgList {
		if ty != val.Ty {
			continue
		}
		if amount >= val.MinAmount && amount <= val.MaxAmount {
			return val
		}
	}
	return PromoDepositConfig{}
}
